package com.sgb.auction.viewmodule;

import androidx.lifecycle.ViewModel;

import com.sgb.auction.base.BaseApi;
import com.sgb.auction.entity.AuctionListEntity;
import com.sgb.auction.entity.RequestBean;
import com.sgb.auction.fragment.FocusAuctionListFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.H5ReEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.List;

/**
 * Time:2021/12/9
 * AUTHOR:F_Q
 * Description:
 */
public class FocusAuctionListModel  extends ViewModel {
    FocusAuctionListFragment fragment;
    private boolean isLastPage;

    public void setActivity(FocusAuctionListFragment focusAuctionListFragment) {
        this.fragment = focusAuctionListFragment;
    }

    /**
     * 获取关注列表信息
     * @param requestBean
     */
    public void getFocusAuctionList(RequestBean requestBean) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        BaseApi.getApi().getfindUserFocusAuctionList(requestBean).enqueue(new ICallBack<BaseEntity<ListResponse<List<AuctionListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<AuctionListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getState().equals(BaseApi.RESPONSE_OK)) {
                    isLastPage = data.getData().getCurrentPage() >= data.getData().getPageSize();
                    fragment.setFocusAuctionList(data.getData().getList(), isLastPage);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    public void getWebView(String no) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        BaseApi.getApi().getUrlSetting("Auctiondetails").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getState().equals(BaseApi.RESPONSE_OK)) {
                    String webUrl = data.getData().getUrl() + "?no=" + no;
                    BaseApi.startWeb(fragment.getActivity(), webUrl,100581);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

}
